﻿using System;
using System.Globalization;
using System.IO;
using System.Windows.Controls;
using RandomSearch.Common;

namespace RandomSearch.ClientUi {
    public class PathValidationRule : ValidationRule {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
            try {
                var path = (string) value;
                if (string.IsNullOrWhiteSpace(path))
                    return new ValidationResult(false, "Path cannot be empty");

                if (!Directory.Exists(path))
                    return new ValidationResult(false, "Path '{0}' not exists".ƒ(path));
            }
            catch (Exception e) {
                return new ValidationResult(false, "Error" + e.Message);
            }

            return new ValidationResult(true, null);
        }
    }
}